package com.alibaba.citrus.ots.platform.enhance.functions.diff.common.dataParser;

import com.alibaba.citrus.ots.platform.enhance.functions.diff.sap.constant.ConsignmentOrderLineDiffStandardFieldDict;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.ConsignmentOrder.ConsignmentOrderLineDTO;
import com.alibaba.citrus.ots.platform.enhance.repository.model.diff.common.FieldLineDTO;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author: qiaojiange
 * @create: 2022/01/24
 * @Description 交货子单数据解析器
 */
@Component
public class ConsignmentOrderLineDataParse extends DataParser {
    /**
     * 数据库字段，映射成对账处理的业务字段(标准字段)
     * key：数据库中的字段，value：转换后的标准字段,这里的 value 字段也不要重复
     */
    private static Map<String, String> dataBaseFiledMapping = new HashedMap();

    static {
        dataBaseFiledMapping.put("outerOrderLineId", ConsignmentOrderLineDiffStandardFieldDict.SAP_ORDER_LINE_ID.getFieldCode());
        dataBaseFiledMapping.put("outerSoLineId", ConsignmentOrderLineDiffStandardFieldDict.SAP_SO_LINE_ID.getFieldCode());
        dataBaseFiledMapping.put("soLineId", ConsignmentOrderLineDiffStandardFieldDict.OTS_SO_LINE_ID.getFieldCode());
        dataBaseFiledMapping.put("scItemId", ConsignmentOrderLineDiffStandardFieldDict.SAP_SC_ITEM_ID.getFieldCode());
        dataBaseFiledMapping.put("qty", ConsignmentOrderLineDiffStandardFieldDict.QTY.getFieldCode());
        dataBaseFiledMapping.put("podStatus", ConsignmentOrderLineDiffStandardFieldDict.POD_STATUS.getFieldCode());
        dataBaseFiledMapping.put("podQty", ConsignmentOrderLineDiffStandardFieldDict.POD_QTY.getFieldCode());
        dataBaseFiledMapping.put("factoryCode", ConsignmentOrderLineDiffStandardFieldDict.FACTORY_CODE.getFieldCode());
        dataBaseFiledMapping.put("inventoryCode", ConsignmentOrderLineDiffStandardFieldDict.INVENTORY_CODE.getFieldCode());
        dataBaseFiledMapping.put("saleUnit", ConsignmentOrderLineDiffStandardFieldDict.SALE_UNIT.getFieldCode());
        dataBaseFiledMapping.put("basicQuantity", ConsignmentOrderLineDiffStandardFieldDict.BASIC_QUANTITY.getFieldCode());
    }

    @Override
    public Map<String, FieldLineDTO> parse(Object obj) {
        Map<String, FieldLineDTO> map = new HashMap<>();
        if (obj instanceof ConsignmentOrderLineDTO) {
            ConsignmentOrderLineDTO consignmentOrderLineDTO = (ConsignmentOrderLineDTO) obj;
            return obtainFieldLineMap(dataBaseFiledMapping, consignmentOrderLineDTO, consignmentOrderLineDTO.getClass());
        }
        return map;
    }

    @Override
    public String obtainProcessType() {
        return "ConsignmentOrderLineDTO";
    }
}
